﻿using System;
using System.ComponentModel;
using RaytracerLib.MathLib;

namespace Raytracer.PropertyGridDecorators
{
    public class Vector2Properties
    {
        public readonly Action<Vector2> Setter;
        public readonly Func<Vector2> Getter;

        public Vector2Properties(Func<Vector2> a_getter, Action<Vector2> a_setter)
        {
            Getter = a_getter;
            Setter = a_setter;
        }

        [TypeConverter(typeof(DoubleConverter))]
        public double X
        {
            get
            {
                return Getter().X;
            }
            set
            {
                Setter(new Vector2(value, Y));
            }
        }

        [TypeConverter(typeof(DoubleConverter))]
        public double Y
        {
            get
            {
                return Getter().Y;
            }
            set
            {
                Setter(new Vector2(X, value));
            }
        }

        public Vector2 ToVector2()
        {
            return new Vector2(X, Y);
        }
    }

    public class Vector2ReadonlyProperties
    {
        private Vector2 m_vector;

        public Vector2ReadonlyProperties(Vector2 a_vector)
        {
            m_vector = a_vector;
        }

        [TypeConverter(typeof(DoubleConverter))]
        public double X
        {
            get
            {
                return m_vector.X;
            }
        }

        [TypeConverter(typeof(DoubleConverter))]
        public double Y
        {
            get
            {
                return m_vector.Y;
            }
        }
    }
}